package com.laviedesfons.jhmtasc.types.internals;

import com.laviedesfons.jhmtasc.annotations.binding.MType;
import com.laviedesfons.jhmtasc.types.interfaces.InternalType;
import fr.x9c.cadmium.kernel.Value;

/**
 *
 * @author Romano
 */
@MType(camlType="int")
public final class PInt implements InternalType {

    private int value;

    public PInt() {  }
    public PInt(int v) {
        value = v;
    }

    public int asInt(){
        return value;
    }

    @Override
    public PInt fromValue(Value v) {
        value = v.asLong();
        return this;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final PInt other = (PInt) obj;
        if (this.value != other.value) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 5;
        hash = 67 * hash + this.value;
        return hash;
    }

    @Override
    public Value toValue() {
        return Value.createFromLong(value);
    }

    @Override
    public String toString() {
        return String.valueOf(value);
    }
}